import axios from 'axios';
import Message from 'element-ui'
import router from '@/router'
import store from '@/store'
const reSend = axios.create({
    // baseURL:'https://www.liulongbin.top:8888/api/private/v1/',
    baseURL: 'http://shiyansong.cn:8888/api/private/v1/',
    // baseURL:'http://123.57.143.201:8888/api/private/v1/',
    // baseURL:'http://82.156.12.132:8081/adminshop/#/login',
    timeout: '5000'
})

reSend.interceptors.request.use(config => {
    let userObj = store.state.userObj.token;
    // console.log(userObj);
    let token = ''
    if(userObj) {
        token = userObj
    }
    /* token携带到请求头中 */
    config.headers.Authorization=token
    return config
}, err => {
    return Promise.reject(err);
})

reSend.interceptors.response.use(res => {
    if(res.data.meta.status == 401) {
        Message({
            message:'登录超时，请重新登录',
            type:'warning'
        })
        router.push('/login');
    }
    return res.data
}, err => {
    return Promise.reject(err);
})

export default reSend
